import AutoImport from 'unplugin-auto-import/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { XTailCoreAutoImports, XTailCoreTypeAutoImports } from '@xtail/unplugin-core'
import { XTailResultAutoImports, XTailResultTypeAutoImports } from '@xtail/unplugin-result'
import { XTailElectronAutoImports, XTailElectronTypeAutoImports } from '@xtail/unplugin-electron'
import { XTailPouchdbAutoImports, XTailPouchdbTypeAutoImports } from '@xtail/unplugin-pouchdb'
import { XTailSSHAutoImports, XTailSSHTypeAutoImports } from '@xtail/unplugin-ssh'
import { XTailVue3AutoImports, XTailVue3TypeAutoImports } from '@xtail/unplugin-vue3'
import { XTailVue3ElAutoImports, XTailVue3ElTypeAutoImports } from '@xtail/unplugin-vue3-el'

const CommonAutoImports = [
  XTailCoreAutoImports(),
  XTailCoreTypeAutoImports(),
  XTailResultAutoImports(),
  XTailResultTypeAutoImports()
]

export const createMainAutoImport = () => {
  return AutoImport({
    dts: 'types/main/auto-imports.d.ts',
    imports: [
      ...CommonAutoImports,
      XTailElectronAutoImports(),
      XTailElectronTypeAutoImports(),
      XTailPouchdbAutoImports(),
      XTailPouchdbTypeAutoImports(),
      XTailSSHAutoImports(),
      XTailSSHTypeAutoImports()
    ],
    dirs: ['src/common', 'src/main/api', 'src/main/utils']
  })
}

export const createPreloadAutoImport = () => {
  return AutoImport({
    dts: 'types/preload/auto-imports.d.ts',
    imports: [],
    dirs: ['src/common', 'src/main/api']
  })
}

export const createRenderAutoImport = () => {
  return AutoImport({
    dts: 'types/auto-imports.d.ts',
    resolvers: [ElementPlusResolver()],
    imports: [
      'vue',
      'vue-router',
      'pinia',
      '@vueuse/core',
      ...CommonAutoImports,
      XTailVue3AutoImports(),
      XTailVue3TypeAutoImports(),
      XTailVue3ElAutoImports(),
      XTailVue3ElTypeAutoImports()
    ],
    dirs: [
      '../common',
      'src/api',
      'src/consts',
      'src/router',
      'src/store',
      'src/types',
      'src/utils'
    ]
  })
}
